package com.lancoo.znbkxx.teacher.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.Ques
import kotlinx.android.synthetic.main.aibk_item_latest_skill.view.*
import java.math.BigDecimal

/**
 * Created by wealive on 2021/3/16.
 *
 *
 */
class WrongCommentAdapter(data: List<Ques>) : BaseQuickAdapter<Ques, BaseViewHolder>(data) {
    init {
        mLayoutResId = R.layout.aibk_item_latest_skill
    }

    @SuppressLint("SetTextI18n")
    override fun convert(helper: BaseViewHolder, item: Ques?) {
        helper.addOnClickListener(R.id.btn_comment)
        with(helper.itemView) {
            if (item?.IsComment == 0) {
                btn_comment.text = "错题讲评"
                btn_comment.setTextColor(Color.parseColor("#00afff"))
                btn_comment.setBackgroundResource(R.drawable.aibk_1v1_bg_e5f8ff)
            } else {
                btn_comment.text = "再次讲评"
                btn_comment.setTextColor(Color.parseColor("#ff6f2f"))
                btn_comment.setBackgroundResource(R.drawable.aibk_1v1_bg_fdf1eb)
            }
            tv_type.text = if (item!!.GenreName.isNotEmpty()) item.GenreName else item.TypeName
            val spanNum = SpannableString("失分率：${BigDecimal(item.LossRate * 100).setScale(0,
                    BigDecimal.ROUND_HALF_UP)}%").apply {
                setSpan(
                        ForegroundColorSpan(Color.parseColor("#788aa4")), 0, lastIndexOf("："),
                        Spanned.SPAN_INCLUSIVE_EXCLUSIVE
                )
                setSpan(
                        ForegroundColorSpan(Color.parseColor("#00afff")), lastIndexOf("："), length,
                        Spanned.SPAN_INCLUSIVE_EXCLUSIVE
                )
            }
            tv_answer_num.text = spanNum
            tv_lost_percent.text = "作答时间：${item.AnswerDate.let {
                it.substring(0, it.lastIndexOf("T")).replace("-", ".")
            }}"
            when (item.TypeNo) {
                "Q", "V", "X", "W", "b", "d", "g", "k", "f" -> iv_type.setImageResource(
                        R.mipmap.aibk_icon_wrong_write)
                "E", "F", "G", "S", "x" -> iv_type.setImageResource(R.mipmap.aibk_icon_wrong_listen)
                else -> iv_type.setImageResource(R.mipmap.aibk_icon_wrong_choice)
            }
        }
    }
}